import Vue from 'vue'
import Router from 'vue-router'
import {
    constantRouterMap
} from '@/config/router.config'


// 问题：在升级了Vue-Router版本到到3.1.0及以上之后，页面在跳转路由控制台会报Uncaught (in promise)的问题
// 解决：对Router原型链上的push、replace方法进行重写，这样就不用每次调用方法都要加上catch。
Router.prototype.push = function push(location, onResolve, onReject) {
    if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
    return originalPush.call(this, location).catch(err => err)
}

Vue.use(Router)



export default new Router({
    mode: 'history',
    base: process.env.VUE_APP_PUBLIC_PATH,
    scrollBehavior: () => ({
        y: 0
    }),
    // routes: [...constantRouterMap, ...asyncRouterMap_bak, notFoundRouter]
    routes: constantRouterMap
})